<?php

class ErrorController extends Zend_Controller_Action {
	protected $_smarty;
	
	public function init()	{
		//echo 'error controller'; exit();
		$this->_smarty = Zend_Registry::get('SMARTY');
	}
	
	public function errorAction() {
		$errors = $this->_getParam ( 'error_handler' );
		
		switch ($errors->type) {
			case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE :
			case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER :
			case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION :
				
				// 404 error -- controller or action not found
				$this->getResponse ()->setHttpResponseCode ( 404 );
				
				$this->_smarty->assign('message', 'Page not found');
				$this->_smarty->display('error/404.tpl');
				return;				
			default :
				// application error
				$this->getResponse ()->setHttpResponseCode ( 500 );

				$this->_smarty->assign('message', 'Application error');				
				break;
		}
		
		// conditionally display exceptions
		if ($this->getInvokeArg ( 'displayExceptions' ) == true) {
			$this->_smarty->assign('exception', $errors->exception);
			$hasException = !empty($errors->exception);	
		}
		
		$this->_smarty->assign('request', $errors->request);
		$this->_smarty->assign('requestParams', $errors->request->getParams());
		
		// display it
		$this->_smarty->display('error/error.tpl');		
	}
}

